<?
/**
*  结算管理
*  2013/7/14 by zh
*/
include("database.php");

include("session.php");
require("ajax_base.php");

$action = $_GET['action'];

if($action == "list") {
	$condition = "1=1";
	if(isset($_GET['date_range'])) {
		$arr = explode("_", $_GET['date_range']);
		$condition .= " and charge_time between '".$arr[0]."' and '".$arr[1]."'";
	}
	if($_SESSION['user_flag'] == "user") {
		$condition .= " and a.user_id = ".$_SESSION['user_id'];
	}
	$sql = "select a.id, b.user_name, b.true_name, charge_price, charge_count, charge_price*charge_count as charget_money, 
	charge_time,charge_desc from qc_money a Left Join qc_user b On a.user_id=b.id where $condition order by a.id desc"; 
	echo to_grid_json($db, $sql, $dic_data, array("true_name"=>"blue_color_mapper","charget_money"=>"red_color_mapper", "charget_count"=>"green_color_mapper", "charge_price"=>"green_color_mapper"));

}  else if($action == "do_charge") {
	if($_SESSION['user_flag'] != "admin") {
		exit; // 只用管理员才能给用户充值
	}
	$_POST['charge_time'] = date('Y-m-d H:i:s');
	$_POST['op_user'] = $_SESSION['user_name'];
	$db->doInsert("qc_money", $_POST);
	$sql = "update qc_user set callable_count=callable_count+".$_POST['charge_count']." where id=".$_POST['user_id'];
	//echo $sql;
	$db->query($sql);
	echo "ok";

} 

?>